define(function(require, exports){
	var $      = require("jquery");
	var util   = require('util');
	var view	= require('@base/view');
	var pubjs  = require('pubjs');
	var kindEditor = require('kindEditor');

	// 多功能编辑窗口
	var Kindeditor = view.container.extend({
		init: function(config, parent){
			config = pubjs.conf(config, {
				'class': 'uk-form M-kindEditor'
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			var el = self.getDOM();
			var c = self.getConfig();
			var doms = self.$doms = {};

			$([
				'<textarea class="editor" id="editor"></textarea>'
			].join('')).appendTo(el);

			// 合并config参数；
			var options = this.$options = util.extend({
				basePath: PUBJS('libs/kindeditor/'),
				resizeType : 1,
				allowPreviewEmoticons : false,
				// allowImageUpload : false,
				uploadJson: '',
				filePostName: 'MaterialFile',
				items: [
					'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
					'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
					'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
					'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
					'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
					'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
					'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
					'anchor', 'link', 'unlink', '|', 'about'
				],
				width: 1000,
				height: 400
			}, c);
			doms.editor = kindEditor.create('#editor', options);
		},
		setData: function(data){
			this.$doms.editor.html(data || '')
			return this;
		},
		getData: function(){
			return util.trim(this.$doms.editor.html());
		},
		reset: function(){
			var editor = this.$doms.editor;
			if(editor){
				editor.remove('#editor');
				editor = kindEditor.create('#editor', this.$options);
			}
			return this;
		}
	});

	exports.base = Kindeditor;

});